/*
 * Licensed to Nanjing RedOrange Co. ltd (RedOrange) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * RedOrange licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package redora.rdo.generator.exceptions;

import java.io.File;
import java.io.FileInputStream;

import org.apache.commons.io.IOUtils;

import redora.rdo.generator.ModelFileHandler;

/**
 * @author jaap
 * 
 * */
public class ModelGenerationException extends Exception {
	private static final long serialVersionUID = 1L;

	/**
	 * Return a string with the contents of the model's XML.
	 * 
	 * @param p
	 *            ModelFileHandler
	 * @param modelFileName
	 *            Filename including .xml suffix but without the path.
	 * @return
	 */
	public static String printModel(ModelFileHandler p, String modelFileName) {
		String retVal = "Failed to retrieve the model file (" + modelFileName
				+ ").";

		try {
			retVal = IOUtils.toString(new FileInputStream(new File(p.modelDir()
					+ modelFileName)));
		} catch (Exception e) {
		}

		return retVal;
	}

	public static String printInclude(ModelFileHandler p, String includeFileName) {
		String retVal = "Failed to retrieve the model file (" + includeFileName
				+ ").";

		try {
			retVal = IOUtils.toString(new FileInputStream(new File(p
					.includeDir()
					+ includeFileName)));
		} catch (Exception e) {
		}

		return retVal;
	}

	public ModelGenerationException(String s, Exception e) {
		super(s, e);
	}

	public ModelGenerationException(String s) {
		super(s);
	}
}
